/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package tenorserver;

import DataModel.NotaryServerAddress;
import Settings.BaseSettings;
import Settings.ISettings;
import java.io.File;
import java.net.InetAddress;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.core.Persister;

/**
 *
 * @author Tomasz Nowak
 */
@Root
public class TenorServerSettings extends BaseSettings implements ISettings
{
	@Element
	private int port;

	@Element
	private NotaryServerAddress[] notaryServerAddresses;

	@Element
	InetAddress listeningAddress;

	public NotaryServerAddress[] getNotaryServerAddresses()
	{
		return notaryServerAddresses;
	}

	public void setNotaryServerAddresses( NotaryServerAddress[] notaryServerAddresses )
	{
		this.notaryServerAddresses = notaryServerAddresses;
	}

	public int getPort()
	{
		return port;
	}

	public void setPort( int port )
	{
		this.port = port;
	}

	public TenorServerSettings()
	{
		this.filename = "tenorserversettings.xml";
	}

	@Override
	public void load()
	{
		try
		{
			Serializer serializer = new Persister();
			File source = new File(this.filename);
			TenorServerSettings settings = serializer.read(TenorServerSettings.class, source);
			this.port = settings.port;
			this.notaryServerAddresses = settings.notaryServerAddresses;
			this.listeningAddress = settings.listeningAddress;
		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}
	}

	public InetAddress getListeningAddress()
	{
		return listeningAddress;
	}

	public void setListeningAddress( InetAddress listeningAddress )
	{
		this.listeningAddress = listeningAddress;
	}

	@Override
	public void save()
	{
		try
		{
			Serializer serializer = new Persister();
			File destination = new File(this.filename);
			serializer.write(this, destination);
		}
		catch ( Exception e )
		{
			e.printStackTrace();
		}
	}
}
